package com.jgybzx.my_time_at_portia.mapper.base;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jgybzx.my_time_at_portia.entity.base.Item;
import com.jgybzx.my_time_at_portia.entity.base.ItemDependency;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

public interface ItemMapper extends BaseMapper<Item> {

    public List<Item> getInfo(String test);


    @Select("SELECT item_id FROM item where item_name =#{test}")
    String test(String test);

    @Select("SELECT * FROM item where item_name =#{test}")
    List<Item> getInfoByItemName(String itemName);

    @Insert("INSERT INTO  error_log (item_id, item_name, reason, create_time) VALUES (#{patentItemId}, #{patentItemName}, #{reason}, #{date})")
    void errorLog(@Param("patentItemId") Integer patentItemId, @Param("patentItemName") String patentItemName, @Param("reason") String reason, @Param("date") Date date);

    @Delete("TRUNCATE TABLE item ")
    void truncateItemsTable();

    @Delete("TRUNCATE TABLE  item_dependency ")
    void truncateItemDependenciesTable();

    @Delete("TRUNCATE TABLE  error_log")
    void truncateErrorLogTable();

    @Update("UPDATE item SET item_id = #{itemId}, item_name = #{itemName}, item_source = #{itemSource}, " +
            "item_classification = #{itemClassification}, item_type = #{itemType}, remark = #{remark}, " +
            "synthesis_formula = #{synthesisFormula} WHERE item_id = #{itemId}")
    int updateById(Item item);

    @Select("SELECT * FROM item_dependency WHERE item_id = #{itemId}")
    List<ItemDependency> getItemDependencies(int itemId);

    @Select("SELECT * FROM item WHERE item_id = #{itemId}")
    Item getItemById(int itemId);
}
